<include file="public/header" />
<include file="public/left" />
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<span class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表">返回上一页</a>
            <div class="subject">
                <h3>线路编辑</h3>
                <h5>网站系统权限资源管理-设置时间</h5>
            </div>
        </div>
    </div>
    <form method="post" enctype="multipart/form-data" id="brandForm">
        <section>
            <ul class="ulColumn2">
                <li>
                    <span class="item_name" style="width:120px;">每隔几天送：</span>
                    <input type="number" min="0" max="30" name="everyday"  value="{$data.every_day?$data.every_day:'';}" />(设置为0 ，则是每天都送)
                </li>
                <li>
                    <span class="item_name" style="width:120px;">几号送：</span>
                    <for start="1" end="32">
                        <input type="checkbox" name="day"  value="{$i}" <if condition="isset($data.days) && is_array($data.days) && in_array($i,$data.days)">checked</if>/>{$i}号
                    </for>

                </li>

                <li id="opt">
                    <span class="item_name" style="width:120px;">每天几时送开始送：</span>
                    {/*
                    <input type="number" min="0" max="23" name="hour" value=""  />
                    <input type="number" min="0" max="59" name="min"  value=""/>
                    */}
                    <input type="button" value="添加" onclick="addParaml(this)">
                    <if condition="!empty($data.every_time)">
                        <volist name="$data.every_time" id="vo">
                            <span class="addtime">
                                配送时间点：
                                <input type="number" min="0" max="23" name="hour[]" value="{$vo[0]}"  />:
                                <input type="number" min="0" max="59" name="min[]"  value="{$vo[1]}"/>
                                <span onclick="deleteParam1(this);" >删除</span>
                            </span>
                        </volist>
                    </if>

                </li>
                <li>
                    <span class="item_name" style="width:370px;color: #dd0000">(温馨提示：每隔几天送与几号送只能选一个，每天几时送可不填)</span>

                </li>
                <li>
                    <input type="hidden" name="id" value="{$data.id?$data.id:'';}">
                    <span class="item_name" style="width:120px;"></span>
                    <input type="button" class="link_btn1 link_btn" value="提交" />
                </li>
            </ul>
        </section>
    </form>
    <script type="text/javascript" src="__STATIC__/admin/js/jquery-ui-1.10.3.min.js"></script>
    <script>
        function deleteParam1(o) {
//            alert('a');
            $(o).parents(".addtime").remove();

            return false;
        }
        function addParaml(obj){
            var li = $(obj).parent('#opt');

//            console.log(li);
            html = '<span class="addtime">'
                    +'<input type="number" min="0" max="23" name="hour[]" value=""  />'+':'
                    +'<input type="number" min="0" max="59" name="min[]"  value=""/>'
                    +'<span onclick="deleteParam1(this);" >删除</span>'
                    +'</span>';
//            console.log(html);
            li.append(html);
            return;
        }
        $(".link_btn1").click(function(){
            obj = document.getElementsByName("day");
            check_val = [];
            for(k in obj){
                if(obj[k].checked)
                    check_val.push(obj[k].value);
            }
            var formData = new FormData();
            var everyday = $('input[name="everyday"]').val();
//            var day = $('input[name="day"]:checked').val();
//            var hour = $('input[name="hour"]').val();
//            var min = $('input[name="min"]').val();
            var id = $('input[name="id"]').val();

            var specs1 = [];
            for(var i = 0; i<$('.addtime').length; i++){
                var optioni = $('.addtime')[i];
                var hour = optioni.children[0].value;
                var min = optioni.children[1].value;
                if(hour == ''){layer.alert('参数填写完整');}
                var spec = {"hour": hour, "min": min};
                specs1.push(spec);
            }
            var specs = JSON.stringify(specs1)
//            console.log(specs);
            formData.append('everyday',everyday);
            formData.append('day',check_val);
            formData.append('specs',specs);
//            formData.append('hour',hour);
//            formData.append('min',min);
            formData.append('id',id);

            $.ajax({
                //url:"https://tjdw.gzldrj.com:441/api/system/goods_edit",
                url:"{:url('Set/routetimeedit')}",
                type:'POST',
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                success:function(result){
//                    console.log(result)
                    if(result.code == 0){
                        layer.alert(result.msg);
                    }else{
                        location.href = "{:url('set/route')}";
                    }
                }
            });
        })
    </script>
</div>
</section>
</body>

</html>